QuestionFollowPortlet = Class.extend({
	init: function()	{
		this.name = "QuestionFollowPortlet";
	},
	
	onReloadPage: function()	{
		this.run();
	},
	
	onBegin: function()	{
		this.registerObserver();
	},
	
	onUnfollowQuestion: function(eventData)	{
		var qid = eventData.qid;
		var obj = this;
		this.onAjax('question', 'unfollow-question', {'id': qid}, 'POST', {
			'onSuccess': function(ret)	{
				obj.onReloadPage();
			}
		});
	},
	
	onFollowQuestion: function(eventData)	{
		var qid = eventData.qid;
		var obj = this;
		this.onAjax('question', 'follow-question', {'id': qid}, 'POST', {
			'onSuccess': function(ret)	{
				obj.onReloadPage();
			}
		});
	},
	
	run: function()	{
		var obj = this;
		var qid = this.getRequest().getParam('qid');
		this.onAjax('question', 'is-user-following', {'id': qid}, 'GET', {
			'onSuccess': function(ret)	{
				obj.model = {};
				obj.model.qid = qid;
				if (ret == true)	{
					obj.model.text = "Ngừng theo dõi câu hỏi";
					obj.model.event = "UnfollowQuestion";
				} else {
					obj.model.text = "Theo dõi câu hỏi";
					obj.model.event = "FollowQuestion";
				}
				obj.getPortletPlaceholder().paintCanvas(obj.render());
			}
		});
	},
	
	onEnd: function()	{
		this.unregisterObserver();
	}
}).implement(PortletInterface).implement(AjaxInterface).implement(RenderInterface).implement(ObserverInterface);